package com.corpgovernment.common.enums;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public enum CorpPayTypeEnum {
    OWN("OWN", "因私"),
    PUB("PUB", "因公"),

    Unknown("Unknown", "未知的");
    private String type;
    private String name;

    CorpPayTypeEnum(String type, String name) {
        this.type = type;
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static String getNameByType(String type) {
        Optional<CorpPayTypeEnum> first = Arrays.stream(CorpPayTypeEnum.values()).filter(e -> Objects.equals(type, e.getType())).findFirst();
        if (first.isPresent()) {
            return first.get().getName();
        }
        return null;
    }

    public static CorpPayTypeEnum getByTypeIgnoreCase(String type) {
        return Arrays.stream(values()).filter((e) -> e.getType().equalsIgnoreCase(type)).findFirst().orElse(Unknown);
    }
}
